package vn.edu.vttu;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainBT5 extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_bt5);
	}
public void tinhtongsonhohonbangN(View view){
	
	
	EditText nhapvao = (EditText) findViewById(R.id.nhap);
	TextView  dayso = (TextView) findViewById(R.id.hienthi);
	TextView Tong = (TextView) findViewById(R.id.tong);
	dayso.setText(null);
	Tong.setText(null);
	int nhapVao = Integer.parseInt(nhapvao.getText().toString());
	
	int M[] = new int[nhapVao];
	int tong1 = 0;
	int tongM = 0;
	TextView tb = (TextView) findViewById(R.id.thongbao);
	tb.setText("Dãy số là: ");
	for (int i = 0; i < nhapVao; i++) {
		
		tong1 = tong1 + (i+1);
		
		if(tong1 <= nhapVao){
			M[i] = i + 1;
			dayso.setText(dayso.getText()+""+(i+1)+" ");
		}
		
	}
	
	for (int j = 0; j < M.length; j++) {
			tongM = M[j] + tongM;
		}
		
		Tong.setText(Tong.getText()+"Tổng các số là: "+tongM);
		
		
	}
	
	
}
